import { defineStore } from 'pinia'
import { FollowInfo } from '@/types'
import { useProfileStore } from './profile'
import { getOtherUserInfo } from '@/api/user'

export const useFollowStore = defineStore('follow', {
	state: () => ({
		followShow: null as FollowInfo | null
	}),
	actions: {
		async showFollow(val: FollowInfo) {
			if (val.show) {
				const profileStore = useProfileStore()
				if (this.followShow?.show && profileStore.profileShow?.show) {
					profileStore.hideProfile()
				}
				if (!val.nickName && !val.userName) {
					const { data } = await getOtherUserInfo({ userId: val.userId })
					val.nickName = data.nickName
					val.userName = data.userName
				}
			}
			this.followShow = val
		}
	},
	getters: {}
	// persist: true
})
